#include <iostream>
using namespace std;
int N;
int a[10];
enum leixing{minimum,maximum};

int findMin(leixing lei = minimum)
{
    int tmp =a[0];
    int index = 0;
    for(int i = 0; i<N; i++)
    {
        switch(lei)
        {
            case minimum:
                if(a[i] < tmp)
                {
                    tmp = a[i];
                    index = i;
                }
                break;
            case maximum:
                if(a[i] > tmp)
                {
                    tmp = a[i];
                    index = i;
                }
                break;
        }
    }
    return index;
}
int main()
{
    
    cin >> N;
    for( int i  = 0; i < N; i++)
        cin >> a[i];
    int indexMin = findMin();
    int tmp = a[0];
    a[0] = a[indexMin];
    a[indexMin] = tmp;
    int indexMax = findMin(maximum);
    tmp = a[N-1];
    a[N-1] = a[indexMax];
    a[indexMax] = tmp;
    for(int i = 0; i<N; i++)
        cout<<a[i]<<" "; 
    
}
